package com.kuangstudy.collection.set;

import java.util.Comparator;
import java.util.TreeSet;

/**
 * ClassName: Demo5
 * date: 2021/07/13 17:05:55
 *
 * @author zlk
 */
public class Demo5 {
    public static void main(String[] args) {
        TreeSet<Student> students = new TreeSet<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {

                int n1 = o1.getName().compareTo(o2.getName());
                int n2 = o1.getAge().compareTo(o2.getAge());
                return n1==0?n1:n2;
            }
        });
        Student s1 = new Student("kk1", 10);
        Student s2 = new Student("kk2", 11);
        Student s3 = new Student("kk2", 11);
        Student s4 = new Student("kk3", 13);
        students.add(s1);
        students.add(s2);
        students.add(s3);
        students.add(s4);
        System.out.println(students);
        students.remove(new Student("kk2",11));
        System.out.println(students);
    }
}
